<?php
class V_admin_model extends TP_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->table = 'v_admin';
    }

    /**
     * [ description]
     * @Name        getList
     * @Description 列表数据
     * @Author      LiAnXu
     * @Date 2020-12-09 13:10:36 星期三
     * @return      [type]                   [description]
     */
    public function getList($param,$export=false){
        if(!$export){
            $connar['pageNo']=$param['pageNo'];
            $connar['pageSize']=$param['pageSize'];
        }        
        unset($param['pageNo']);
        unset($param['pageSize']);       
        // 非管理员不获取超级管理员
        $acc=$this->get_single(array('uuid'=>$_SESSION[SESS_HEADER]['uuid']));
        $role=explode(',',$acc['role_id']);
        if(in_array(1,$role)){
            $connar['where']='1=1';
        }else{
            $connar['where']=sql_format("role_id<>{0}",1);
        }
        
        foreach ($param as $k => $v) {
            if($k=='role_id'){
                $connar['where'].=sql_format(" and  find_in_set({0},{1})",$v,$k);
            }else{
                $connar['where'].=sql_format(" and {0} like '%{1}%'",$k,$v);
            }
        }
        if($export){
            $list=$this->get_list_full($connar);
            foreach ($list as $k => $v) {
                $list[$k]['valid_char']=(new EnableState)->show($v['valid']);
            }
        }else{
            $data=$this->get_page_list($connar);
            $list=$data;
            foreach ($list['ret'] as $k => $v) {
                $list['ret'][$k]['valid_char']=(new EnableState)->show($v['valid']);
            }
        }
        return $list;
    }

}
